package com.yantong.constant;

import java.util.*;

/**
 * 优惠券使用范围限制
 * @author kanghaixin
 * @date 2018/9/25.14:16
 */
public enum TicketRange {

    RANGE_NO_LIMIT(null, "无限制"),
    RANGE_NEW_MEMBER(1, "限新人"),
    RANGE_PRODUCT(2, "限商品"),
    RANGE_CATEGORY(3, "限分类");


    private Integer code;
    private String name;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    TicketRange(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    private static Map<Integer, String> all = new HashMap<>();
    static {
        for (TicketRange ticketRange : EnumSet.allOf(TicketRange.class)) {
            if (ticketRange.getCode() == null) {
                continue;
            }
            all.put(ticketRange.code, ticketRange.name);
        }
    }
    public static String get(Integer code) {
        return all.get(code);
    }


    public static List<Map<String, Object>> listTicketRanges() {
        List<Map<String, Object>> list = new ArrayList<>();

        for (TicketRange ticketRange : EnumSet.allOf(TicketRange.class)) {
            if (ticketRange.getCode() == null) {
                continue;
            }

            Map<String, Object> item = new HashMap<>();
            item.put("code", ticketRange.getCode());
            item.put("name", ticketRange.getName());
            list.add(item);
        }
        return list;
    }
}
